<?php
	
class Table_Vips extends Zend_Db_Table_Abstract
{
    protected $_name    = 'vip';
    protected $_primary = 'VIP_NUMERO';
    protected $_sequence = TRUE; //la table a un autoincr�ment
 	
  
    public function getPremiereLettreTousVip(){
    	
        return $this->fetchAll($this
        	->select()
        	->from($this,array('lettre' => 'distinct substring(VIP_NOM,1,1)'))
        	->order('lettre')
        	->distinct()
        	
        	);			
    }
	
	public function getNom($premiereLettre){
		return $this->fetchAll($this
			->select()
			->where('substring(VIP_NOM,1,1) = ?', $premiereLettre)
			
			);
	}
	
	public function getAllRemplirVip(){	
    $req= $this
    	->select()
    	->from($this,'*');

		return $this->fetchAll($req);   	
    }
	
	public function getVip($idVip){
		return $this->fetchRow($this
			->select()
			->where('VIP_NUMERO= ?', $idVip));
	}
	
	public function getAllVip(){
		return $this->fetchAll($this
									->select('VIP_NUMERO', 'VIP_NOM'));
	}
	
	public function getAllVips(){
		return $this->fetchAll($this
									->select());
	}
	
	
	public function insertVip($numNation, $nom, $prenom, $sexe, $dateNaiss, $txt){
		$data = array('NATIONALITE_NUMERO'=> $numNation, 'VIP_NOM' => $nom,
					'VIP_PRENOM' => $prenom, 'VIP_SEXE' => $sexe, 'VIP_NAISSANCE' => $dateNaiss,
					'VIP_TEXTE' => $txt, 'VIP_DATE_INSERTION' => new Zend_Db_Expr('CURDATE()'));
		$this->insert($data);
	}

	public function getNumVip($nom, $prenom){
		return $this->fetchRow($this
									->select('VIP_NUMERO')
									->where('VIP_NOM = ?', $nom)
									->where('VIP_PRENOM = ?', $prenom));
	}
	public function supprVip($id){
		$this->delete('VIP_NUMERO ='.(int)$id);
	}
	
	public function getInfosVip($id) {
		return $this->fetchRow($this
			->select()
			->from($this, array('*'))
			->where('vip_numero = ?', $id)
			);
	
	}

	public function getVips($id) {
		return $this->fetchAll($this->select()
									->where('vip_nom = ?', $id)
								);
	}
	
	public function getAllNumVip() {
		 return $this->fetchAll($this
        	->select()
        	->from($this,array('vip_numero'))
        	);
	}
	
	public function getVipsByLettre($lettre)
    {
    	return $this->fetchAll($this->select()
    								->where('VIP_NOM like ?',$lettre.'%')
    								->order('VIP_NOM'));
    }
	
}